| <?php |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| namespace Eloquent\Schemer\Validation; |
| |
| use DateTime; |
| use Eloquent\Equality\Comparator; |
| use Eloquent\Schemer\Constraint\ArrayValue; |
| use Eloquent\Schemer\Constraint\ConstraintInterface; |
| use Eloquent\Schemer\Constraint\DateTimeValue; |
| use Eloquent\Schemer\Constraint\Generic; |
| use Eloquent\Schemer\Constraint\NumberValue; |
| use Eloquent\Schemer\Constraint\ObjectValue; |
| use Eloquent\Schemer\Constraint\PlaceholderSchema; |
| use Eloquent\Schemer\Constraint\Schema; |
| use Eloquent\Schemer\Constraint\StringValue; |
| use Eloquent\Schemer\Constraint\Visitor\ConstraintVisitorInterface; |
| use Eloquent\Schemer\Pointer\Pointer; |
| use Eloquent\Schemer\Pointer\PointerInterface; |
| use Eloquent\Schemer\Value; |
| use LogicException; |
| use Zend\Validator\EmailAddress; |
| use Zend\Validator\Hostname; |
| use Zend\Validator\Ip; |
| use Zend\Validator\Uri as UriValidator; |
| use Zend\Validator\ValidatorInterface; |
| |
| class ConstraintValidator implements |
| ConstraintValidatorInterface, |
| ConstraintVisitorInterface |
| { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function __construct( |
| $formatValidationEnabled = null, |
| Comparator $comparator = null, |
| ValidatorInterface $emailValidator = null, |
| ValidatorInterface $hostnameValidator = null, |
| ValidatorInterface $ipv4AddressValidator = null, |
| ValidatorInterface $ipv6AddressValidator = null, |
| ValidatorInterface $uriValidator = null |
| ) { |
| if (null === $formatValidationEnabled) { |
| $formatValidationEnabled = true; |
| } |
| if (null === $comparator) { |
| $comparator = new Comparator; |
| } |
| if (null === $emailValidator) { |
| $emailValidator = new EmailAddress; |
| } |
| if (null === $hostnameValidator) { |
| $hostnameValidator = new Hostname; |
| } |
| if (null === $ipv4AddressValidator) { |
| $ipv4AddressValidator = new Ip(array( |
| 'allowipv4' => true, |
| 'allowipv6' => false, |
| 'allowipvfuture' => false, |
| 'allowliteral' => false, |
| )); |
| } |
| if (null === $ipv6AddressValidator) { |
| $ipv6AddressValidator = new Ip(array( |
| 'allowipv4' => false, |
| 'allowipv6' => true, |
| 'allowipvfuture' => false, |
| 'allowliteral' => false, |
| )); |
| } |
| if (null === $uriValidator) { |
| $uriValidator = new UriValidator('Eloquent\Schemer\Uri\Uri'); |
| } |
| |
| $this->formatValidationEnabled = $formatValidationEnabled; |
| $this->comparator = $comparator; |
| $this->emailValidator = $emailValidator; |
| $this->hostnameValidator = $hostnameValidator; |
| $this->ipv4AddressValidator = $ipv4AddressValidator; |
| $this->ipv6AddressValidator = $ipv6AddressValidator; |
| $this->uriValidator = $uriValidator; |
| } |
| |
| |
| |
| |
| public function setFormatValidationEnabled($formatValidationEnabled) |
| { |
| $this->formatValidationEnabled = $formatValidationEnabled; |
| } |
| |
| |
| |
| |
| public function formatValidationEnabled() |
| { |
| return $this->formatValidationEnabled; |
| } |
| |
| |
| |
| |
| public function comparator() |
| { |
| return $this->comparator; |
| } |
| |
| |
| |
| |
| public function emailValidator() |
| { |
| return $this->emailValidator; |
| } |
| |
| |
| |
| |
| public function hostnameValidator() |
| { |
| return $this->hostnameValidator; |
| } |
| |
| |
| |
| |
| public function ipv4AddressValidator() |
| { |
| return $this->ipv4AddressValidator; |
| } |
| |
| |
| |
| |
| public function ipv6AddressValidator() |
| { |
| return $this->ipv6AddressValidator; |
| } |
| |
| |
| |
| |
| public function uriValidator() |
| { |
| return $this->uriValidator; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| public function validate( |
| ConstraintInterface $constraint, |
| Value\ConcreteValueInterface &$value, |
| PointerInterface $entryPoint = null |
| ) { |
| if (null === $entryPoint) { |
| $entryPoint = new Pointer; |
| } |
| |
| $this->clear(); |
| |
| $this->pushContext(array($value, $entryPoint)); |
| $result = $constraint->accept($this); |
| |
| $this->clear(); |
| |
| return $result; |
| } |
| |
| |
| |
| |
| |
| |
| public function visitSchema(Schema $schema) |
| { |
| $result = $this->result($schema); |
| if (null !== $result) { |
| return $result; |
| } |
| |
| $result = $this->register($schema, $this->createResult()); |
| |
| foreach ($schema->constraints() as $constraint) { |
| $result = $result->merge($constraint->accept($this)); |
| } |
| |
| if ($result->isValid()) { |
| $result->addMatch($this->createMatch($schema)); |
| } |
| |
| return $result; |
| } |
| |
| |
| |
| |
| |
| |
| public function visitPlaceholderSchema(PlaceholderSchema $schema) |
| { |
| return $schema->innerSchema()->accept($this); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| public function visitEnumConstraint(Generic\EnumConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| foreach ($constraint->values() as $enumValue) { |
| if ($this->comparator()->equals($value, $enumValue)) { |
| return $this->createResult(); |
| } |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitTypeConstraint(Generic\TypeConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| $isValid = false; |
| foreach ($constraint->valueTypes() as $valueType) { |
| if ($valueType === Value\ValueType::ARRAY_TYPE()) { |
| $isValid = $value instanceof Value\ArrayValue; |
| } elseif ($valueType === Value\ValueType::BOOLEAN_TYPE()) { |
| $isValid = $value instanceof Value\BooleanValue; |
| } elseif ($valueType === Value\ValueType::DATE_TIME_TYPE()) { |
| $isValid = $value instanceof Value\DateTimeValue; |
| } elseif ($valueType === Value\ValueType::INTEGER_TYPE()) { |
| $isValid = $value instanceof Value\IntegerValue; |
| } elseif ($valueType === Value\ValueType::NULL_TYPE()) { |
| $isValid = $value instanceof Value\NullValue; |
| } elseif ($valueType === Value\ValueType::NUMBER_TYPE()) { |
| $isValid = $value instanceof Value\NumberValueInterface; |
| } elseif ($valueType === Value\ValueType::OBJECT_TYPE()) { |
| $isValid = $value instanceof Value\ObjectValue; |
| } elseif ($valueType === Value\ValueType::STRING_TYPE()) { |
| $isValid = $value instanceof Value\StringValue; |
| } |
| |
| if ($isValid) { |
| return $this->createResult(); |
| } |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitAllOfConstraint(Generic\AllOfConstraint $constraint) |
| { |
| if (1 === count($constraint->schemas())) { |
| $schemas = $constraint->schemas(); |
| |
| return $schemas[0]->accept($this); |
| } |
| |
| $result = $this->createResult(); |
| foreach ($constraint->schemas() as $schema) { |
| $result = $result->merge($schema->accept($this)); |
| } |
| |
| return $result; |
| } |
| |
| |
| |
| |
| |
| |
| public function visitAnyOfConstraint(Generic\AnyOfConstraint $constraint) |
| { |
| if (1 === count($constraint->schemas())) { |
| $schemas = $constraint->schemas(); |
| |
| return $schemas[0]->accept($this); |
| } |
| |
| foreach ($constraint->schemas() as $schema) { |
| $result = $schema->accept($this); |
| if ($result->isValid()) { |
| return $result; |
| } |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitOneOfConstraint(Generic\OneOfConstraint $constraint) |
| { |
| if (1 === count($constraint->schemas())) { |
| $schemas = $constraint->schemas(); |
| |
| return $schemas[0]->accept($this); |
| } |
| |
| $validResults = array(); |
| foreach ($constraint->schemas() as $schema) { |
| $result = $schema->accept($this); |
| if ($result->isValid()) { |
| $validResults[] = $result; |
| } |
| } |
| |
| if (1 === count($validResults)) { |
| return array_shift($validResults); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitNotConstraint(Generic\NotConstraint $constraint) |
| { |
| if (!$constraint->schema()->accept($this)->isValid()) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| public function visitMaximumPropertiesConstraint(ObjectValue\MaximumPropertiesConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\ObjectValue || |
| $value->count() <= $constraint->maximum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitMinimumPropertiesConstraint(ObjectValue\MinimumPropertiesConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\ObjectValue || |
| $value->count() >= $constraint->minimum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitRequiredConstraint(ObjectValue\RequiredConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\ObjectValue || |
| $value->has($constraint->property()) |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitPropertiesConstraint(ObjectValue\PropertiesConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if (!$value instanceof Value\ObjectValue) { |
| return $this->createResult(); |
| } |
| |
| $result = $this->createResult(); |
| $matchedProperties = array(); |
| |
| |
| foreach ($constraint->schemas() as $property => $schema) { |
| if ($value->has($property)) { |
| $matchedProperties[$property] = true; |
| $result = $result->merge( |
| $this->validateObjectProperty($property, $schema) |
| ); |
| } elseif (null !== $schema->defaultValue()) { |
| $result = $result->merge( |
| $this->createResult( |
| array(), |
| array($this->createDefaultValueMatch($schema, $property)) |
| ) |
| ); |
| } |
| } |
| |
| |
| foreach ($constraint->patternSchemas() as $pattern => $schema) { |
| $pattern = $this->wrapPattern($pattern); |
| |
| foreach ($value->keys() as $property) { |
| if (preg_match($pattern, $property)) { |
| $matchedProperties[$property] = true; |
| $result = $result->merge( |
| $this->validateObjectProperty($property, $schema) |
| ); |
| } |
| } |
| } |
| |
| |
| foreach ($value->keys() as $property) { |
| if (!array_key_exists($property, $matchedProperties)) { |
| $result = $result->merge( |
| $this->validateObjectProperty( |
| $property, |
| $constraint->additionalSchema() |
| ) |
| ); |
| } |
| } |
| |
| return $result; |
| } |
| |
| |
| |
| |
| |
| |
| public function visitAdditionalPropertyConstraint(ObjectValue\AdditionalPropertyConstraint $constraint) |
| { |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitDependencyConstraint(ObjectValue\DependencyConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\ObjectValue || |
| !$value->has($constraint->property()) |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $constraint->schema()->accept($this); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| public function visitItemsConstraint(ArrayValue\ItemsConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if (!$value instanceof Value\ArrayValue) { |
| return $this->createResult(); |
| } |
| |
| $result = $this->createResult(); |
| $matchedIndices = array(); |
| |
| |
| foreach ($constraint->schemas() as $index => $schema) { |
| if ($value->has($index)) { |
| $matchedIndices[$index] = true; |
| $result = $result->merge( |
| $this->validateArrayIndex($index, $schema) |
| ); |
| } elseif (null !== $schema->defaultValue()) { |
| $result = $result->merge( |
| $this->createResult( |
| array(), |
| array($this->createDefaultValueMatch($schema, $index)) |
| ) |
| ); |
| } |
| } |
| |
| |
| foreach ($value->keys() as $index) { |
| if (!array_key_exists($index, $matchedIndices)) { |
| $result = $result->merge( |
| $this->validateArrayIndex( |
| $index, |
| $constraint->additionalSchema() |
| ) |
| ); |
| } |
| } |
| |
| return $result; |
| } |
| |
| |
| |
| |
| |
| |
| public function visitAdditionalItemConstraint(ArrayValue\AdditionalItemConstraint $constraint) |
| { |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitMaximumItemsConstraint(ArrayValue\MaximumItemsConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\ArrayValue || |
| $value->count() <= $constraint->maximum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitMinimumItemsConstraint(ArrayValue\MinimumItemsConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\ArrayValue || |
| $value->count() >= $constraint->minimum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitUniqueItemsConstraint(ArrayValue\UniqueItemsConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\ArrayValue || |
| !$constraint->value() || |
| $this->comparator->equals( |
| $value->value(), |
| $this->unique($value->value()) |
| ) |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| public function visitMaximumLengthConstraint(StringValue\MaximumLengthConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\StringValue || |
| mb_strlen($value->value(), 'UTF-8') <= $constraint->maximum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitMinimumLengthConstraint(StringValue\MinimumLengthConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\StringValue || |
| mb_strlen($value->value(), 'UTF-8') >= $constraint->minimum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitPatternConstraint(StringValue\PatternConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\StringValue || |
| preg_match( |
| $this->wrapPattern($constraint->pattern()), |
| $value->value() |
| ) |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitDateTimeFormatConstraint(StringValue\DateTimeFormatConstraint $constraint) |
| { |
| if (!$this->formatValidationEnabled()) { |
| return $this->createResult(); |
| } |
| |
| $value = $this->currentValue(); |
| if (!$value instanceof Value\StringValue) { |
| return $this->createResult(); |
| } |
| |
| $formats = array( |
| DateTime::ISO8601, |
| 'Y-m-d\TH:i:s\Z', |
| 'Y-m-d\TH:i:sP', |
| ); |
| foreach ($formats as $format) { |
| if (false !== DateTime::createFromFormat($format, $value->value())) { |
| return $this->createResult(); |
| } |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitEmailFormatConstraint(StringValue\EmailFormatConstraint $constraint) |
| { |
| if (!$this->formatValidationEnabled()) { |
| return $this->createResult(); |
| } |
| |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\StringValue || |
| $this->emailValidator()->isValid($value->value()) |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitHostnameFormatConstraint(StringValue\HostnameFormatConstraint $constraint) |
| { |
| if (!$this->formatValidationEnabled()) { |
| return $this->createResult(); |
| } |
| |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\StringValue || |
| $this->hostnameValidator()->isValid($value->value()) |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitIpv4AddressFormatConstraint(StringValue\Ipv4AddressFormatConstraint $constraint) |
| { |
| if (!$this->formatValidationEnabled()) { |
| return $this->createResult(); |
| } |
| |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\StringValue || |
| $this->ipv4AddressValidator()->isValid($value->value()) |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitIpv6AddressFormatConstraint(StringValue\Ipv6AddressFormatConstraint $constraint) |
| { |
| if (!$this->formatValidationEnabled()) { |
| return $this->createResult(); |
| } |
| |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\StringValue || |
| $this->ipv6AddressValidator()->isValid($value->value()) |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitUriFormatConstraint(StringValue\UriFormatConstraint $constraint) |
| { |
| if (!$this->formatValidationEnabled()) { |
| return $this->createResult(); |
| } |
| |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\StringValue || |
| $this->uriValidator()->isValid($value->value()) |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| public function visitMultipleOfConstraint(NumberValue\MultipleOfConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if (!$value instanceof Value\NumberValueInterface) { |
| return $this->createResult(); |
| } |
| |
| if ( |
| $value instanceof Value\FloatingPointValue || |
| is_float($constraint->quantity()) |
| ) { |
| if (0 == fmod($value->value(), $constraint->quantity())) { |
| return $this->createResult(); |
| } |
| } else { |
| if (0 === $value->value() % $constraint->quantity()) { |
| return $this->createResult(); |
| } |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitMaximumConstraint(NumberValue\MaximumConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\NumberValueInterface || |
| $value->value() <= $constraint->maximum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitMinimumConstraint(NumberValue\MinimumConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\NumberValueInterface || |
| $value->value() >= $constraint->minimum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| public function visitMaximumDateTimeConstraint(DateTimeValue\MaximumDateTimeConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\DateTimeValue || |
| $value->value() <= $constraint->maximum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| public function visitMinimumDateTimeConstraint(DateTimeValue\MinimumDateTimeConstraint $constraint) |
| { |
| $value = $this->currentValue(); |
| if ( |
| !$value instanceof Value\DateTimeValue || |
| $value->value() >= $constraint->minimum() |
| ) { |
| return $this->createResult(); |
| } |
| |
| return $this->createSingleIssueResult($constraint); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| protected function validateObjectProperty($property, Schema $schema) |
| { |
| list($value, $pointer) = $this->currentContext(); |
| $this->pushContext(array( |
| $value->get($property), |
| $pointer->joinAtoms($property) |
| )); |
| $result = $schema->accept($this); |
| $this->popContext(); |
| |
| return $result; |
| } |
| |
| |
| |
| |
| |
| |
| |
| protected function validateArrayIndex($index, Schema $schema) |
| { |
| list($value, $pointer) = $this->currentContext(); |
| $this->pushContext(array( |
| $value->get($index), |
| $pointer->joinAtoms(strval($index)) |
| )); |
| $result = $schema->accept($this); |
| $this->popContext(); |
| |
| return $result; |
| } |
| |
| |
| |
| |
| protected function pushContext(array $context) |
| { |
| array_push($this->contextStack, $context); |
| } |
| |
| |
| |
| |
| protected function popContext() |
| { |
| if (null === array_pop($this->contextStack)) { |
| throw new LogicException('Validation context stack is empty.'); |
| } |
| } |
| |
| protected function clear() |
| { |
| $this->contextStack = array(); |
| $this->results = array(); |
| } |
| |
| |
| |
| |
| |
| protected function currentContext() |
| { |
| $count = count($this->contextStack); |
| if ($count < 1) { |
| throw new LogicException('Current validation context is undefined.'); |
| } |
| |
| return $this->contextStack[$count - 1]; |
| } |
| |
| |
| |
| |
| |
| protected function currentValue() |
| { |
| list($value) = $this->currentContext(); |
| |
| return $value; |
| } |
| |
| |
| |
| |
| |
| protected function currentPointer() |
| { |
| list(, $pointer) = $this->currentContext(); |
| |
| return $pointer; |
| } |
| |
| |
| |
| |
| |
| |
| |
| protected function createResult(array $issues = null, array $matches = null) |
| { |
| return new Result\ValidationResult($issues, $matches); |
| } |
| |
| |
| |
| |
| |
| |
| protected function createSingleIssueResult(ConstraintInterface $constraint) |
| { |
| return $this->createResult(array($this->createIssue($constraint))); |
| } |
| |
| |
| |
| |
| |
| |
| protected function createIssue(ConstraintInterface $constraint) |
| { |
| list($value, $pointer) = $this->currentContext(); |
| |
| return new Result\ValidationIssue( |
| $constraint, |
| $value, |
| $pointer |
| ); |
| } |
| |
| |
| |
| |
| |
| |
| protected function createMatch(Schema $schema) |
| { |
| list(, $pointer) = $this->currentContext(); |
| |
| return new Result\ValidationMatch( |
| $schema, |
| $pointer |
| ); |
| } |
| |
| |
| |
| |
| |
| |
| |
| protected function createDefaultValueMatch(Schema $schema, $atom) |
| { |
| list(, $pointer) = $this->currentContext(); |
| |
| return new Result\DefaultValueMatch( |
| $schema, |
| $pointer->joinAtoms($atom) |
| ); |
| } |
| |
| |
| |
| |
| |
| |
| protected function unique(array $array) |
| { |
| $unique = array(); |
| foreach ($array as $value) { |
| if (!in_array($value, $unique, true)) { |
| $unique[] = $value; |
| } |
| } |
| |
| return $unique; |
| } |
| |
| |
| |
| |
| |
| |
| protected function wrapPattern($pattern) |
| { |
| return sprintf('/%s/', str_replace('/', '\\/', $pattern)); |
| } |
| |
| |
| |
| |
| |
| |
| |
| protected function register( |
| Schema $schema, |
| Result\ValidationResult $result |
| ) { |
| $this->results[$this->generateVisitKey($schema)] = $result; |
| |
| return $result; |
| } |
| |
| |
| |
| |
| |
| |
| protected function result(Schema $schema) |
| { |
| $key = $this->generateVisitKey($schema); |
| if (array_key_exists($key, $this->results)) { |
| return $this->results[$key]; |
| } |
| |
| return null; |
| } |
| |
| |
| |
| |
| |
| |
| protected function generateVisitKey(Schema $schema) |
| { |
| return sprintf( |
| '%s.%s', |
| spl_object_hash($schema), |
| spl_object_hash($this->currentValue()) |
| ); |
| } |
| |
| private $formatValidationEnabled; |
| private $comparator; |
| private $emailValidator; |
| private $hostnameValidator; |
| private $ipv4AddressValidator; |
| private $ipv6AddressValidator; |
| private $uriValidator; |
| |
| private $contextStack; |
| private $results; |
| } |